package krakow.ae.knp.wikiboard.communication;

import java.net.*;
import java.io.*;

public class JustClientWiki {
    /* 
     * jest to narazie MIRROR  --nie modyfikowac-- 
     * mozna uruchomic serwer ktory jest w branches
     * i uruchomic kilka razy ten plik z RunFile 
     * a w konsolach obserwowac co sie dzieje
     */
    public static void main(String [] args) throws Exception {
        
        String nowaLinia = System.getProperty("line.separator");
        
        BufferedReader standardInput = new BufferedReader(new InputStreamReader(System.in));
        
        Socket socket =  new Socket("localhost",4444);
        
        System.out.println("Server - port: " + socket.getPort());
        System.out.println("Server - localPort: " + socket.getLocalPort());
        
        ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
        ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
        boolean admin = in.readBoolean();
        if(admin) {
            for (int i=0; i<100; i++) {
                out.writeObject(new Integer(i));
                out.flush();
                out.reset();
                System.out.println(in.readObject());
                Thread.sleep(1000);
            }
        } else {
            while(true) {
                System.out.println(in.readObject());
            }
        }
    }
}
